#ifndef NIXIE_TUBE_3_H
#define NIXIE_TUBE_3_H

#include "hardware.h"

#define NT3_TUBE1_TYPE GPIOC // 数段控制外设
#define NT3_TUBE2_TYPE GPIOD
#define NT3_TUBE3_TYPE GPIOD

#define NT3_A_TYPE GPIOD // 数字控制外设
#define NT3_B_TYPE GPIOC
#define NT3_C_TYPE GPIOA
#define NT3_D_TYPE GPIOD
#define NT3_E_TYPE GPIOD
#define NT3_F_TYPE GPIOC
#define NT3_G_TYPE GPIOB
#define NT3_DP_TYPE GPIOA

#define NT3_TUBE1_PIN GPIO_Pin_7 // 数段控制引脚
#define NT3_TUBE2_PIN GPIO_Pin_2
#define NT3_TUBE3_PIN GPIO_Pin_3

#define NT3_A_PIN GPIO_Pin_1 // 数字控制引脚
#define NT3_B_PIN GPIO_Pin_3
#define NT3_C_PIN GPIO_Pin_2
#define NT3_D_PIN GPIO_Pin_6
#define NT3_E_PIN GPIO_Pin_4
#define NT3_F_PIN GPIO_Pin_4
#define NT3_G_PIN GPIO_Pin_5
#define NT3_DP_PIN GPIO_Pin_1

#define NT_TUBE_HUNDREDS(state) (state == 1) ? (GPIO_WriteBit(NT3_TUBE1_TYPE, NT3_TUBE1_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_TUBE1_TYPE, NT3_TUBE1_PIN, Bit_RESET))
#define NT_TUBE_TES(state) (state == 1) ? (GPIO_WriteBit(NT3_TUBE2_TYPE, NT3_TUBE2_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_TUBE2_TYPE, NT3_TUBE2_PIN, Bit_RESET))
#define NT_TUBE_UNIT(state) (state == 1) ? (GPIO_WriteBit(NT3_TUBE3_TYPE, NT3_TUBE3_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_TUBE3_TYPE, NT3_TUBE3_PIN, Bit_RESET))

#define NT_NUM_A(state) (state == 1) ? (GPIO_WriteBit(NT3_A_TYPE, NT3_A_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_A_TYPE, NT3_A_PIN, Bit_RESET))
#define NT_NUM_B(state) (state == 1) ? (GPIO_WriteBit(NT3_B_TYPE, NT3_B_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_B_TYPE, NT3_B_PIN, Bit_RESET))
#define NT_NUM_C(state) (state == 1) ? (GPIO_WriteBit(NT3_C_TYPE, NT3_C_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_C_TYPE, NT3_C_PIN, Bit_RESET))
#define NT_NUM_D(state) (state == 1) ? (GPIO_WriteBit(NT3_D_TYPE, NT3_D_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_D_TYPE, NT3_D_PIN, Bit_RESET))
#define NT_NUM_E(state) (state == 1) ? (GPIO_WriteBit(NT3_E_TYPE, NT3_E_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_E_TYPE, NT3_E_PIN, Bit_RESET))
#define NT_NUM_F(state) (state == 1) ? (GPIO_WriteBit(NT3_F_TYPE, NT3_F_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_F_TYPE, NT3_F_PIN, Bit_RESET))
#define NT_NUM_G(state) (state == 1) ? (GPIO_WriteBit(NT3_G_TYPE, NT3_G_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_G_TYPE, NT3_G_PIN, Bit_RESET))
#define NT_NUM_DP(state) (state == 1) ? (GPIO_WriteBit(NT3_DP_TYPE, NT3_DP_PIN, Bit_SET)) : (GPIO_WriteBit(NT3_DP_TYPE, NT3_DP_PIN, Bit_RESET))

typedef enum
{
    DISP_VOLTAGE = 0x00, // 显示电压
    DISP_ELECTRICITY,    // 显示电流
    DISP_VOLTAGE_POWER   // 显示功率

} display_type_t;

typedef struct
{
    uint16_t display_num : 10; // 显示的3位数字（max：999）
    uint16_t display_type : 2; // 数据显示类型
    uint16_t dp_digit : 2;     // 小数点显示位置0 - 不显示; 1 - 个位; 2 - 十位; 3 - 百位;

} nixie_tube_3_infor_t;

void nixie_tube_3_init(void);
void nixie_tube_num_update(float value);
void nixie_tube_num_refresh(void);
void nixie_tube_num_display(uint8_t num);

extern nixie_tube_3_infor_t nt3_infor;

#endif
